package exodia;
/**
 * ModGames (C) 2007 Pedro Miller Rabinovitch.
 * 
 * Permission is hereby granted to copy and use this material for any free or educational purpose.
 * Please do not use this for commercial purposes before letting me know (but it'll be fine).
 * 
 * Contact me via gmail, account pedromr
 * http://exodia.org
 * 
 * $Id: Actor.java 41 2007-12-04 00:57:21Z pedromr $
 */

import javax.microedition.lcdui.Graphics;

/**
 * @author Miller Our better Sprite. Correct rotation to avoid bad
 *         implementations and allow interesting image customization.
 */
public class Actor {
	protected int x, y;
	protected int transform;

	protected AnimDefinition animDef;
	protected ActorDefinition actorDef;

	protected int currFrame;
	private boolean visible = true;

	public Actor() {
	}

	public Actor(ActorDefinition actorDefinition) {
		this.actorDef = actorDefinition;
		setAnimation(0);
	}

	public void setAnimation(int which) {
		if (which > actorDef.arrAnimations.length || which < 0) {
			throw new IllegalArgumentException("No animation " + which);
		}
		animDef = actorDef.arrAnimations[which];
		transform = actorDef.arrTransforms[which];
	}

	public int getWidth() {
		return animDef.getWidth(currFrame);
	}

	public int getHeight() {
		return animDef.getHeight(currFrame);
	}

	public void nextFrame() {
		currFrame = (currFrame + 1) % animDef.getNumberOfFrames();
	}

	public void setAnim(AnimDefinition anim) {
		this.animDef = anim;
	}

	public void setPosition(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public void paint(Graphics g, int offsetX, int offsetY) {
		if( visible )
			animDef.drawFrame(g, offsetX + x, offsetY + y, currFrame, transform);
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getTransform() {
		return transform;
	}

	public void setTransform(int transform) {
		this.transform = transform;
	}

	public AnimDefinition getAnim() {
		return animDef;
	}

	public void paint(Graphics g) {
		paint(g, 0, 0);
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public boolean getVisible() {
		return this.visible;
	}
}
